<template>
	<view class="content" :style="$theme.pageStyle">


		<div class="detail_box">
			<view class="aui-flex">
				<div class="aui-flex-box">
					<h2>评价用户</h2>
				</div>
			</view>
			<view class="author_box">
				<view class="author_boxs">
					<view class="box5">
						<view class="box6">
							<u-avatar :src="authorDetail.avatar" mode="circle" :show-level="true"></u-avatar>
						</view>
						<view class="box7">
							<view class="" style="display: flex;height: 22px;">
								<text class="word8">{{authorDetail.real_name}} 律师</text>
							</view>
							<!-- <text lines="1" class="txt2">
								{{authorDetail.city}} ·
								<block v-for="(typeitem, indexitem) in authorDetail.realm" :key='indexitem'>
									{{typeitem}} ·
								</block>
							</text> -->
						</view>
						<view class="box8"></view>
					</view>
				</view>
			</view>
		</div>


		

		<div class="detail_box">
			<view class="aui-flex">
				<div class="aui-flex-box">
					<h2>评价内容</h2>
				</div>
			</view>
			<view class="formbox" style="margin-top: 20px;">
				<u-rate :count="counts" v-model="count_number" activeIcon="heart-fill" inactiveIcon="heart"></u-rate>
			</view>
			<u--form labelPosition="top" :model="FormData" ref="form1">
				<u-form-item label=" " prop="intro" ref="item3" labelWidth="150">
					<u--textarea placeholder="不低于5个字" v-model="content" count></u--textarea>
				</u-form-item>
			</u--form>
		</div>
		
		<div class="detail_box">
			<view class="aui-flex">
				<div class="aui-flex-box">
					<h2>是否匿名</h2>
				</div>
			</view>
			<view class="formbox" style="margin-top: 20px;">
				<u-switch v-model="hide" @change="Otherchange"></u-switch>
			</view>
		</div>
		


		<div class="detail_box">
			<view class="aui-flex">
				<div class="aui-flex-box">
					<h2>评价图片</h2>
				</div>
			</view>
			<view class="author_box">
				<u-upload :fileList="fileList1" @afterRead="afterReadbg" @delete="deletePicbg" name="1" multiple
					:maxCount="9"></u-upload>
			</view>
		</div>


		<view class="" style="margin: 10px;margin-top: 25px;">
			<view class="btbs" @click="submit()">确定</view>
		</view>
		
		
		<view style="height: 40px;"></view>
		
	</view>
</template>

<script>
	import $H from "@/common/js/request.js"
	export default {
		data() {
			return {
				lawyer_id: '',
				order_id: '',
				fileList1: [],
				notice: '',
				rules: [],
				User: {},
				Usercontact: {},
				detail: {},
				counts: 5,
				is_hide: 0,
				hide: false,
				count_number: '',
				authorDetail: uni.getStorageSync('evaluate'),
				content: '',
				FormData: {
					content: '',
					mark: 0
				}
			}
		},
		onLoad(opt) {
			this.lawyer_id = opt.id
			this.order_id = opt.order_id
		},
		methods: {
			Otherchange(e) {
				if (e === true) {
					this.is_hide = 1
				} else {
					this.is_hide = 0
				}
			},
			// 删除图片
			deletePicbg(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterReadbg(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				let token = uni.getStorageSync('token')
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: this.$url + 'upload/image',
						filePath: url,
						header: {
							token
						},
						name: 'file',
						fileType: 'image',
						success: (res) => {
							if (res.code = 1) {
								let data = JSON.parse(res.data)
								setTimeout(() => {
									resolve(data.data.url)
								}, 1000)
							}

						}
					});
				})
			},

			submit() {
				
				if(this.content == ""){
					return uni.showToast({
						title: '请输入评价内容!',
						icon: none
					})
				}
				
				if(this.count_number == 0){
					return uni.showToast({
						title: '请选择评分!',
						icon: none
					})
				}
				
				$H.post('order/consultevaluate', {
					lawyer_id: this.lawyer_id,
					order_id: this.order_id,
					content : this.content,
					imglist : this.fileList1,
					count_number : this.count_number,
					is_hide :this.is_hide,
				}, {
					token: true
				}).then(res => {
					if (res.code == 1) {
						
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
						
						uni.navigateBack();
						
							
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				})



			}
		}
	}
</script>

<style lang="scss" scoped>
	.detail_box {
		margin: 10px;
		background: #fff;
		border-radius: 10px;
		padding: 10px;
		box-shadow: 0 .2rem 1rem rgba(0, 0, 0, .05);
		transition: .3s all cubic-bezier(0, 1, 0.95, 1.05);

		.detail_detail {
			margin-top: 10px;
		}

		.detail_detail_img image {
			width: 100%;
			border-radius: 10px;
			margin-top: 20px;
		}

		.aui-flex {
			display: flex;
			-webkit-box-align: center;
			-webkit-align-items: center;
			align-items: center;
			padding: 0px 15px 0px 15px;
			position: relative;

			.aui-flex-box {
				-webkit-box-flex: 1;
				-webkit-flex: 1;
				flex: 1;
				min-width: 0;
				font-size: 14px;
				color: #333;
			}
		}
	}

	.aui-flex-box h2 {
		color: #424242;
		font-weight: 500;
		font-size: 14px;
		position: relative;
	}

	.aui-flex-box h2:after {
		content: '';
		position: absolute;
		z-index: 0;
		top: 0.2rem;
		left: -15px;
		width: 0.25rem;
		height: 75%;
		border-radius: 1px;
		background-color: var(--color-primary);
	}

	.author_box {
		display: flex;
		margin-top: 10px;

		.author_boxs {
			height: 120rpx;
			background: url(http://tuchuangwng.oss-cn-beijing.aliyuncs.com/2022/05/16/cdaa54c8376cc.png) 100% no-repeat;
			align-self: center;
			width: 100%;
			justify-content: center;
			align-items: flex-start;
			padding-left: 30rpx;
			display: flex;
			flex-direction: column;
			border-radius: 60rpx;
		}

		.box5 {
			width: 100%;
			height: 80rpx;
			flex-direction: row;
			display: flex;
		}

		.box6 {
			// border-radius: 50%;
			// background: url(http://tuchuangwng.oss-cn-beijing.aliyuncs.com/2022/05/16/45b95253023fb.png) 100% 100% no-repeat;
			width: 15%;
		}

		.pic3 {
			position: absolute;
			left: 0rpx;
			top: 0rpx;
			width: 80rpx;
			height: 80rpx;
		}

		.box7 {
			width: 100%;
			height: 72rpx;
			display: flex;
			flex-direction: column;
			margin: 0px 0 0 20rpx;
		}

		.word8 {
			height: 22px;
			display: block;
			overflow-wrap: break-word;
			color: rgba(48, 48, 48, 1);
			font-size: 28rpx;
			font-family: PingFangSC-Semibold;
			white-space: nowrap;
			line-height: 22px;
			text-align: left;
		}

		.txt2 {
			width: 144rpx;
			height: 22px;
			display: block;
			overflow-wrap: break-word;
			color: rgba(152, 153, 155, 1);
			font-size: 24rpx;
			font-family: PingFangSC-Regular;
			white-space: nowrap;
			line-height: 22px;
			text-align: left;
			align-self: flex-start;
		}

		.box8 {
			// width: 12rpx;
			// height: 22rpx;
			// background: url(http://tuchuangwng.oss-cn-beijing.aliyuncs.com/2022/05/16/0a4679f9880d3.png) 100% no-repeat;
			// display: flex;
			// flex-direction: column;
			// margin: 29rpx 0 0 335rpx;
		}
	}

	.author_span {}

	.author_span image {
		margin-left: 10px;
		width: 20px;
		height: 20px;
	}

	.btbs {
		width: 100%;
		// margin: 10px;
		background: var(--color-primary);
		height: 50px;
		line-height: 50px;
		color: #fff;
		text-align: center;
		border-radius: 15px;
	}
</style>